package student.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import student.aistar.model.dto.GenerateOrderDTO;
import student.aistar.model.dto.OrderAndOrderDetailDTO;
import student.aistar.model.entity.*;
import student.aistar.service.*;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 本类用来演示:
 *
 * @author: qinFeng
 * @date: 2021/9/24 20:52
 */
@Controller
@RequestMapping("/buy")
public class BuyController {


    @Autowired
    ICartService cartService;
    @Autowired
    IUserService userService;
    @Autowired
    IIndexService iIndexService;
    @Autowired
    IOrderService orderService;
    @Autowired
    IProductService productService;

    /**
     * 确认购买产生订单信息,,,跳转的是两个不同的页面, 记住了
     * @param paraCartProduct
     * @param indexAddress
     * @param session
     * @param model
     * @return
     */
    @GetMapping("/order_sub_success")
    public String orderSubSuccess(String paraCartProduct, Integer indexAddress, HttpSession session, Model model){
        List<Navclass> navClassList = iIndexService.navClassList();
        model.addAttribute("navClassList", navClassList);
        User user = (User) session.getAttribute("user");
        OrderAndOrderDetailDTO orderAndOrderDetailDTO = orderService.generateOrder(paraCartProduct, indexAddress, user);
        model.addAttribute("orderAndOrderDetailDTO", orderAndOrderDetailDTO);
        return "mi/buy/order_sub_succes";
    }


    /**
     * 跳转的是两个不同的页面, 记住了
     * @param orderId
     * @param session
     * @param model
     * @return
     */
    @GetMapping("/goToBuy")
    public String goToBuy(Integer orderId, HttpSession session, Model model){
        List<Navclass> navClassList = iIndexService.navClassList();
        model.addAttribute("navClassList", navClassList);
        User user = (User) session.getAttribute("user");

        OrderAndOrderDetailDTO orderAndOrderDetailDTO = orderService.goToBuy(user, orderId);
        model.addAttribute("orderAndOrderDetailDTO", orderAndOrderDetailDTO);

        return "mi/buy/order_sub_succes";
    }
}
